package com.jzdjt.tool;

 
public class ChangePinYin {
    /**
     * 根据用户输出的汉字提取出每个汉字的拼音首字母
     * @author Ganwb
     * 
     */
    
    private String getstring;//用户输入的字符串
    private String backgetchar="";//用户输入汉字的拼音简码
    
    public void setGetString(String getstring){
        this.getstring=getstring;
        String str[]=this.getstring.split("");//将字符串转换成数组,数组第0位为""
        int length=str.length;//获得数组长度
        int start=1;//设置循环初始值
        byte[] a=null;
        String getchar="";//存储汉字拼音首字母
        while(start<length){
            a=str[start].getBytes();
            if(a.length>1){
                int asc=256*(a[0]+256)+(a[1]+256);
                if(asc>=45217 && asc<=45252){
                    getchar="A";
                }else if(asc>=45253 && asc<=45760){
                    getchar="B";
                }else if(asc>=45761 && asc<=46317){
                    getchar="C";
                }else if(asc>=46318 && asc<=46825){
                    getchar="D";
                }else if(asc>=46826 && asc<=47009){
                    getchar="E";
                }else if(asc>=47010 && asc<=47296){
                    getchar="F";
                }else if(asc>=47297 && asc<=47613){
                    getchar="G";
                }else if(asc>=47614 && asc<=48118){
                    getchar="H";
                }else if(asc>=48119 && asc<=49061){
                    getchar="J";
                }else if(asc>=49062 && asc<=49323){
                    getchar="K";
                }else if(asc>=49324 && asc<=49895){
                    getchar="L";
                }else if(asc>=49896 && asc<=50370){
                    getchar="M";
                }else if(asc>=50371 && asc<=50613){
                    getchar="N";
                }else if(asc>=50614 && asc<=50621){
                    getchar="O";
                }else if(asc>=50622 && asc<=50905){
                    getchar="P";
                }else if(asc>=50906 && asc<=51386){
                    getchar="Q";
                }else if(asc>=51387 && asc<=51445){
                    getchar="R";
                }else if(asc>=51446 && asc<=52217){
                    getchar="S";
                }else if(asc>=52218 && asc<=52967){
                    getchar="T";
                }else if(asc>=52698 && asc<=52979){
                    getchar="W";
                }else if(asc>=52980 && asc<=53640){
                    getchar="X";
                }else if(asc>=53689 && asc<=54480){
                    getchar="Y";
                }else if(asc>=54481 && asc<=62289){
                    getchar="Z";
                }               
            }
            else{
                getchar=str[start];
            }
            backgetchar+=getchar;
            start++;
        }
    }
    public String getGetstring() {
        return getstring;
    }
    public String getBackgetchar() {
        
        return backgetchar;
    }
    
    public static void main(String[] args) {
    	ChangePinYin cp=new ChangePinYin();
        cp.setGetString("北京奥运");
        System.out.println(cp.getGetstring());
        System.out.println(cp.getBackgetchar());
    }
}
